﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;


public partial class admin_view_buy : System.Web.UI.Page
{
    string ss;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["w_id"] = Request.QueryString["id"].ToString();
        BindGridviewData();
        Label67.Text = Session["w_id"].ToString();

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        ss = Session["w_id"].ToString();
        Label1.Text = Session["email"].ToString();


        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Request.QueryString["id"].ToString(); ;
            // Image1 .ImageUrl ="property.ashx?p_id=" + str.ToString();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM property_rent where c_id='" + Session["w_id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {
                //Client Details 
                txtclient_fullname1.Text = dr[6].ToString();
                txtclient_fullname2.Text = dr[7].ToString();
                lblssn.Text = dr[8].ToString();
                lblphone.Text = dr[9].ToString();
                lblctype.Text = dr[3].ToString();

                //End Client Details 

                //Client Address
                lblsteet.Text = dr[85].ToString();
                lblhouse.Text = dr[10].ToString();
                lblneigh.Text = dr[12].ToString();
                lblcity.Text = dr[11].ToString();
                lblcount.Text = dr[15].ToString();
                lblzip.Text = dr[19].ToString();
                Label97.Text = dr[16].ToString();
                Label98.Text = dr[17].ToString();
                Label99.Text = dr[18].ToString();
                Label100.Text = dr[15].ToString();
                Label101.Text = dr[20].ToString();
                Label102.Text = dr[19].ToString();


                Label103.Text = dr[22].ToString();
                Label104.Text = dr[23].ToString();
                Label105.Text = dr[24].ToString();
                Label106.Text = dr[25].ToString();
                Label107.Text = dr[26].ToString();
                Label108.Text = dr[27].ToString();
                Label109.Text = dr[31].ToString();
                Label110.Text = dr[32].ToString();
                Label111.Text = dr[33].ToString();
                Label112.Text = dr[34].ToString();
                Label113.Text = dr[35].ToString();
                Label114.Text = dr[36].ToString();
                lblptype.Text = dr[37].ToString();
                lblptype1.Text = dr[38].ToString();
                Label115.Text = dr[39].ToString();
                Label116.Text = dr[40].ToString();
                Label117.Text = dr[41].ToString();
                Label118.Text = dr[42].ToString();
                Label119.Text = dr[43].ToString();
                Label120.Text = dr[44].ToString();
                Label121.Text = dr[45].ToString();
                Label122.Text = dr[46].ToString();
                Label123.Text = dr[47].ToString();
                Label124.Text = dr[48].ToString();
                Label125.Text = dr[49].ToString();
                Label126.Text = dr[50].ToString();
                Label127.Text = dr[51].ToString();
                Label128.Text = dr[52].ToString();
                Label129.Text = dr[53].ToString();
                Label130.Text = dr[54].ToString();
                Label131.Text = dr[55].ToString();
                Label132.Text = dr[56].ToString();
                Label133.Text = dr[57].ToString();
                Label134.Text = dr[58].ToString();
                Label135.Text = dr[59].ToString();
                Label136.Text = dr[60].ToString();
                Label137.Text = dr[61].ToString();
                Label138.Text = dr[62].ToString();
                Label139.Text = dr[63].ToString();
                Label140.Text = dr[64].ToString();
                Label141.Text = dr[84].ToString();

                TextBox1.Text = dr[79].ToString();


            //    lblssn.Text = dr[10].ToString();
               // lblcity.Text = dr[16].ToString();



                if (Label109.Text == "בחר")
                {
                    Label109.Text = "-";
                }

                else
                {
                    Label109.Text = dr[31].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label112.Text == "בחר")
                {
                    Label112.Text = "-";
                }

                else
                {
                    Label112.Text = dr[34].ToString();
                }

                //////////////////////////////////////////////////////
              
                if (lblptype.Text == "בחר")
                {
                    lblptype.Text = "-";
                }

                else
                {
                    lblptype.Text = dr[37].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label117.Text == "בחר")
                {
                    Label117.Text = "-";
                }

                else
                {
                    Label117.Text = dr[41].ToString();
                }



                //////////////////////////////////////////////////////
            

                if (Label139.Text == "בחר" || Label139.Text == "שדה למילוי עצמי")
                {
                    Label139.Text = "-";
                }

                else
                {
                    Label139.Text = dr[63].ToString();
                }

       

                //////////////////////////////////////////////////////



                if (Label113.Text == "בחר" || Label113.Text == "שדה למילוי עצמי")
                {
                    Label113.Text = "-";
                }

                else
                {
                    Label113.Text = dr[35].ToString();
                }



                //////////////////////////////////////////////////////
                if (Label108.Text == "בחר" || Label108.Text == "שדה למילוי עצמי")
                {
                    Label108.Text = "";
                }

                else
                {
                    Label108.Text = dr[27].ToString();
                }

                //////////////////////////////////////////////////////


                if (Label106.Text == "בחר" || Label106.Text == "שדה למילוי עצמי")
                {
                    Label106.Text = "-";
                }

                else
                {
                    Label106.Text = dr[25].ToString();
                }

                //////////////////////////////////////////////////////

                if (Label118.Text == "בחר" || Label118.Text == "שדה למילוי עצמי")
                {
                    Label118.Text = "-";
                }

                else
                {
                    Label118.Text = dr[42].ToString();
                }

                //////////////////////////////////////////////////////



                if (Label125.Text == "בחר" || Label125.Text == "שדה למילוי עצמי")
                {
                    Label125.Text = "-";
                }

                else
                {
                    Label125.Text = dr[49].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label127.Text == "בחר" || Label127.Text == "שדה למילוי עצמי")
                {
                    Label127.Text = "-";
                }

                else
                {
                    Label127.Text = dr[51].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label129.Text == "בחר" || Label129.Text == "שדה למילוי עצמי")
                {
                    Label129.Text = "-";
                }

                else
                {
                    Label129.Text = dr[53].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label131.Text == "בחר" || Label131.Text == "שדה למילוי עצמי")
                {
                    Label131.Text = "-";
                }

                else
                {
                    Label131.Text = dr[55].ToString();
                }

                //////////////////////////////////////////////////////
                if (Label133.Text == "בחר" || Label133.Text == "שדה למילוי עצמי")
                {
                    Label133.Text = "-";
                }

                else
                {
                    Label133.Text = dr[57].ToString();
                }

                //////////////////////////////////////////////////////

                //////////////////////////////////////////////////////
                if (Label135.Text == "בחר" || Label135.Text == "שדה למילוי עצמי")
                {
                    Label135.Text = "-";
                }

                else
                {
                    Label135.Text = dr[59].ToString();
                }

                //////////////////////////////////////////////////////


                if (lblsteet.Text == "בחר")
                {
                    lblsteet.Text = "-";
                }

                else
                {
                    lblsteet.Text = dr[85].ToString();
                }


                //////////////////////////////////////////////////////
                if (lblhouse.Text == "בחר")
                {
                    lblhouse.Text = "-";
                }

                else
                {
                    lblhouse.Text = dr[10].ToString();
                }


                //////////////////////////////////////////////////////
                if (Label109.Text == "שדה למילוי עצמי")
                {
                    Label109.Text = "-";
                }

                else
                {
                    Label109.Text = dr[31].ToString();
                }


                //////////////////////////////////////////////////////
                if (Label112.Text == "שדה למילוי עצמי")
                {
                    Label112.Text = "-";
                }

                else
                {
                    Label112.Text = dr[34].ToString();
                }

                //////////////////////////////////////////////////////
                if (lblptype.Text == "שדה למילוי עצמי")
                {
                    lblptype.Text = "-";
                }

                else
                {
                    lblptype.Text = dr[37].ToString();
                }

                //////////////////////////////////////////////////////
                if (lblptype1.Text == "שדה למילוי עצמי")
                {
                    lblptype1.Text = "-";
                }

                else
                {
                    lblptype1.Text = dr[38].ToString();
                }
                //////////////////////////////////////////////////////
                if (Label120.Text == "שדה למילוי עצמי" || Label120.Text == "בחר")
                {
                    Label120.Text = "-";
                }

                else
                {
                    Label120.Text = dr[44].ToString();


                    //////////////////////////////////////////////////////

            
                   


                }


                dr.Close();
            }
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {




        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select c_id from property_rent where c_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["w_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("view-task.aspx");
            // con.Close();


        }
    }


    protected void Save_Click(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {


        //  string pageurl="Default.aspx?Id=6&RollNo=15";

        //Response.Write(<script> window.open( ‘"+pageurl+"’,'_blank' ); </script>);
        //Response.End();
    }

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    private void BindGridviewData()
    {
        SqlConnection con = null;
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from files where id='" + Request.QueryString["id"].ToString() + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gvDetails.DataSource = ds;
        gvDetails.DataBind();

        con.Close();
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string file_path = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file_path + "\"");
        Response.TransmitFile(Server.MapPath(file_path));
        Response.End();
    }

    protected void GridView2_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    }
}